$(function(){
	var basePath=$("#basepath").val();
	$("#projectFilter_go").click(function(){
		var clgId=$("#projectFilter_form select[name='college']").val();
		window.location=basePath+"admin/project/showProject/"+clgId+"/1";
	});
	$(".project_desc_show").click(function(){
		var desc=$(this).find(".description_div").html();
		$("#project_description_box .modal-body").html(desc);
	});
	$(".project_edit").click(function(){
		var prjId=$(this).attr("data-projectId");
		window.location=basePath+"admin/project/showUpdateProject/"+prjId;
	});
	$("#student_add").click(function(){
		window.location=basePath+"admin/student/showInsertStudent";
	});
	$(".project_delete").click(function(){
		$("#project_delete_box input[name='projectId']").val($(this).attr("data-projectId"));
	});
	$("#project_delete_box_delete").click(function(){
		var prjId=$("#project_delete_box input[name='projectId']").val();
		$.get(basePath+ "admin/project/deleteProject/"+prjId,{},
				function(data,textStatus){
					if(textStatus=="success"){
						switch (data) {
						case "-1":
							alert("请勿进行非法操作");
							window.location=basePath;
							break;
						case "0":
							noty({text:"删除成功,正在刷新"});
							$("#project_delete_box").modal('hide');
							history.go(0);
							break;
						default:
							alert("登陆状态已过期,请重新登陆");
							window.location=basePath;
							break;
						}
					}
			}, "text");
	});
	$("#project_add_excel").click(function(){
		$("#project_add_excel_box_confirm").unbind();
		$("#project_add_excel_box_file_name").html("未选择");
		$("#project_add_excel_box_alert_container").html("");
		$("#project_add_excel_box_file").show();
		$("#project_add_excel_box_progress").hide();
		$("#project_add_excel_box_progress div").css("width","0%");
	});
	$("#project_add_excel_box_file input[type='file']").fileupload({  
	    url:basePath+"admin/project/insertProjectByExcel",
	    autoUpload:false,
	    done:function(e,result){  
			noty({text:"导入完成,正在处理"});
	    	window.location=basePath+"/admin/project/showInsertReport";
	    } ,
	    progress:function(e,result){
	    	var progress=parseInt(result.loaded / result.total * 100, 10);
	    	$("#project_add_excel_box_progress div").css("width",progress+"%");
	    },
	    add:function(e,result){
	    	var fileName=result.files[0].name.toLowerCase();
			var isExcel=/(\.xlsx{0,1})$/.test(fileName);
			if(isExcel){
				$("#project_add_excel_box_alert_container .wrong_file_error").alert('close');
				$("#project_add_excel_box_file_name").html(fileName);
			}else{
				makeAlert("请选择正确的excel文件","error",$("#project_add_excel_box_alert_container"),"wrong_file_error");
				$("#project_add_excel_box_file_name").html("请选择");
				return;
			}
			$("#project_add_excel_box_confirm").unbind();
			$("#project_add_excel_box_confirm").click(function(){
				$("#project_add_excel_box_file_name").html("正在上传:"+fileName);
				$("#project_add_excel_box_file").hide();
				$("#project_add_excel_box_progress").show();
				result.submit();
			});
	    }
	}) ;
});